Skip to content

fix(packs): leanPack acpTags states ref stability across compression - #419

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-25_fix-leanpack-ref-stability-wording
Sep 25, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-25_fix-leanpack-ref-stability-wording

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #417

Problem

The built-in leanPack pi-adapter acpTags line (src/packs.ts:225) told models:

Refs may be renumbered after compression. If a ref is stale or missing, call acp_status …

This contradicts the implementation. assignRefs (src/refs.ts:52-84) copies the existing byRaw/byRef maps through, skips already-mapped messages (if (map.byRaw[message.id]) continue;), and allocates new refs monotonically from nextIndex via allocateFreeRef — refs are never reissued within a session state. Numbering restarts only across a generation switch / native-compaction reset, which already carry dedicated error text. So within one session state, compression does not renumber. Consistent with the kernel contract "Message Ids Are Never Reused".

Change

One model-facing line in src/packs.ts (leanPack adapters.pi.promptSections.acpTags), first sentence only:

  • old: Refs may be renumbered after compression.
  • new: Message refs remain stable across compression within the same session state.

The rest of the line is retained verbatim (stale-ref recovery: acp_status { scope: "uncompressed" }, retry in-turn with reported refs, never guess offsets, batch ranges). The retained clause still covers the rare real restart case (a new session state after reset) by telling the model exactly how to recover if it ever hits a stale ref. Wording follows the issue's suggested phrasing (pi-side-consistent, token-lean for the lean pack).

Behavior change (disclosure)

Model-facing prompt text only — no programmatic semantics, error shape, or wire format touched. Old → new: the false per-compress renumbering expectation is removed; models are now told refs are stable within a session state, plus the unchanged recovery procedure. Why: the old line taught models to expect a renumbering that no longer happens, contradicting both the ref-immutability invariant and the dedicated reset-path error texts, and could cause unnecessary acp_status calls.

Relationship to #385 / #387

Same fix as part 2 of PR #387 ("leanPack ref-stability wording"), split out so the uncontroversial factual correction lands independently of #387's protected-zone acp_status-guidance change (part 1), which was shelved pending root-cause investigation. When #387 is revisited, drop its src/packs.ts change (keep only its src/compress.ts part) to avoid a duplicate edit on this line. Discovered independently from billion-context-pi#541; the pi default-prompt analog was fixed there in billion-context-pi#543.

Cross-repo follow-up (not done here)

billion-context-pi CONFIGURATION.md:890 describes the lean pack with "renumbering recovery" wording; needs a matching update once this kernel change ships. Out of scope for this repo — flagging for tracking.

Tests

String-pinned regression in tests/packs.test.ts: asserts the stability sentence is present, "may be renumbered" is gone, and all four retained failure-handling rules survive. Fails pre-fix, passes post-fix.

Verification (rebased onto current origin/master fafc9c8, v0.0.89)

  • npm run typecheck: clean
  • npm test: 1109/1109 pass
  • npm run build: success
  • diff: 2 files, +29/−1; every diff line prettier-conformant (repo-wide format:check reports pre-existing non-conformant files on master itself; this diff adds zero new violations)

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-25_fix-leanpack-ref-stability-wording (3b4dce3)

Option A — Install from npm PR tag (recommended)

In your adapter project:

npm install acp-kernel@pr-419

Each push to this PR publishes a new version under the pr-419 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf acp-kernel-pr419.tgz
npm install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review of PR #419 (fixes #417) — verified on branch 2026-09-25_fix-leanpack-ref-stability-wording @ d67f15e, rebased onto master fafc9c8.

方向关(原 issue): Bug 属实。核对 src/refs.ts:52-84:assignRefs 先复制 existing.byRaw/byRef(L57-58),已映射消息直接跳过(if (map.byRaw[message.id]) continue; L69),新 ref 从 nextIndex 起经 allocateFreeRef 单调分配(L76 → L90-97,只向前扫、candidate++,绝不重发)。同一会话状态内 refs 确实从不重编号。旧文案教模型期待一个不会发生的重编号 → 根因是过时的 model-facing 措辞,本 PR 精准纠正它(不是治标),与 "Message Ids Are Never Reused" 契约一致。

回归审查: 改动只碰 leanPack pi acpTags 首句。全仓 grep:"may be renumbered" 仅出现在 src/packs.ts:225,且没有任何既有测试钉住它——删除不破坏任何东西。default pack、其他 adapter、程序语义、错误形状、wire 格式均未触碰。行为变更仅限 model-facing 提示文本,且已按规范披露(旧值→新值+原因)。无意外漂移。

代码: 单行改动,最小且准确。"Message refs remain stable across compression within the same session state." 精确圈定了保证范围;保留的从句仍覆盖真实的 reset 重启场景(新会话状态),恢复流程逐字未动。

测试有效性: 新增 tests/packs.test.ts 用例有牙——断言稳定性句存在、"may be renumbered" 消失、且四条保留的失败处理规则全部存活(acp_status {scope:"uncompressed"}、同轮重试、禁止猜偏移、批量提交)。读的是真实 leanPack.surface.adapters.pi.promptSections.acpTags 字符串而非本地副本。既能抓回滚,也能抓误删恢复流程。

diff 整洁度: 2 files, +29/−1——每一行都服务于目的(修复 + 钉住它的测试)。Prettier 干净(pr-validation 的 format 门绿)。

CI: 全绿 — pr-validation ✓ / test(22) ✓ / test(24) ✓ / build-artifact ✓;mergeable_state: clean。(本地未复跑全套:CI 已跑门+Node 22/24 矩阵,本地缺 node_modules 无法加载 tsx,属环境缺口非代码问题。)

说明:#387 的重叠(重审时丢掉其 src/packs.ts hunk)与跨仓 billion-context-pi CONFIGURATION.md:890 的同步,均已由作者正确标记为延后/跟踪项,不在本仓范围。

结论:可以合并。我不会执行合并(PR 合并仅人工操作)。

中文摘要:修复了 leanPack 提示词里“压缩后 refs 可能重新编号”的错误说法(实现上同一会话状态内 refs 从不重发),改为准确表述并保留原有失效恢复规则,补了带断言的回归测试,CI 全绿,可以合并。

ework-agent added 2 commits September 25, 2026 21:27
The leanPack pi-adapter acpTags line claimed "Refs may be renumbered
after compression," contradicting assignRefs (src/refs.ts): within a
single session state existing byRaw/byRef refs are copied through and
new refs allocate monotonically from nextIndex — never reissued.
Numbering restarts only across a generation switch / native-compaction
reset, which already carry dedicated error text. Replace the false
claim with "Message refs remain stable across compression within the
same session state." and retain the stale-ref recovery rules
(acp_status { scope: "uncompressed" }, no offset guessing, batch
ranges). String-pinned regression test added.

Fixes #417
Adopts the broader regression net from duplicate PR #429: asserts
/renumber/i appears nowhere in either builtin pack (defaultPack,
leanPack), complementing the existing lean acpTags string-pins.
Red pre-fix, green post-fix.
@ranxianglei
ranxianglei force-pushed the 2026-09-25_fix-leanpack-ref-stability-wording branch from d67f15e to 3b4dce3 Compare September 25, 2026 13:30
@ranxianglei
ranxianglei merged commit 05a2955 into master Sep 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lean prompt pack 错误声称压缩后 refs 可能重新编号(与 billion-context-pi#541 同类)

1 participant